package com.Babysleep.Activity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

import com.Babysleep.R;

/**
 * 前四个页面的基类。
 * 
 */
public class PlayActivity extends BasicActivity {
	protected int visiblity_counter = 300;
	private Listener mylistener = new Listener();

	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		new MyHandler().sendEmptyMessageDelayed(1, 5000);
		findViewById(R.id.frame).setOnTouchListener(mylistener);
		super.onStart();
	}

	class MyHandler extends Handler {

		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			super.handleMessage(msg);
			visiblity_counter = visiblity_counter - 5;
			if (visiblity_counter > 0)
				sendEmptyMessageDelayed(1, 5000);
			else {
				visiblity_counter = 300;
				set_invisible();
			}
		}
	}

	public void set_invisible() {
		findViewById(R.id.cycle).setVisibility(View.INVISIBLE);
		findViewById(R.id.daojishi).setVisibility(View.INVISIBLE);
	}

	public void set_visible() {
		findViewById(R.id.cycle).setVisibility(View.VISIBLE);
		findViewById(R.id.daojishi).setVisibility(View.VISIBLE);
	}

	public class Listener implements OnTouchListener {

		@Override
		public boolean onTouch(View v, MotionEvent event) {
			if (v.getId() == R.id.frame
					&& event.getAction() == event.ACTION_DOWN) {
				if (findViewById(R.id.daojishi).getVisibility() == View.VISIBLE)
					set_invisible();
				else {
					set_visible();
				}
			}
			return false;
		}
	}
}
